/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package downloadmanager.event;

import java.util.ArrayList;
import java.util.List;

/**
 * Provide ability to manage and invoke a list of XEventListener
 * @author Administrator
 */
public class XEvent<T> {

    private List<XEventListener<T>> listeners = new ArrayList<XEventListener<T>>();

    public synchronized void subscribe(XEventListener<T> listener) {
        listeners.add(listener);
    }

    public synchronized void unsubscribe(XEventListener<T> listener) {
        listeners.remove(listener);
    }

    // call this method whenever you want to notify
    //the event listeners of the particular event
    public synchronized void fire(Object sender, T args) {
        for (XEventListener<T> l : listeners) {
            l.eventFired(sender, args);
        }
    }
}
